package com.yzjs.common.util.httpclient;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;

import java.time.LocalDate;

public class HttpClientFactory {

//	private static final int SO_TIMEOUT = 3000;

	private static PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();

	static {
		cm.setMaxTotal(1000);

		cm.setDefaultMaxPerRoute(50);
		cm.setValidateAfterInactivity(1000);
	}

	private static final Integer REQ_TIMEOUT =  3000;
	//请求超时时间ms
	private static final Integer CONN_TIMEOUT = 3000;
	//连接超时时间ms
	private static final Integer SOCK_TIMEOUT = 5000;
	//读取超时时间ms

	public static CloseableHttpClient get(){
		RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(REQ_TIMEOUT).setConnectTimeout(CONN_TIMEOUT).setSocketTimeout(SOCK_TIMEOUT).build();
		return HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build();
	}

}
